package com.hasidea.android.smswish;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;

public class ContactAdapter extends BaseAdapter {

	LayoutInflater m;

	List<ContactBean>  mlist = new ArrayList<ContactBean>();
	
	
	public ContactAdapter(Context c) {
		m = LayoutInflater.from(c);
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return mlist.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mlist.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (null == convertView) {
			convertView = m.inflate(R.layout.row_slccontact, null);
		}
		TextView tvName = (TextView) convertView
				.findViewById(R.id.contactName_TextView);
		TextView tvPhone = (TextView) convertView
				.findViewById(R.id.contactPhone_TextView);
		CheckBox chk = (CheckBox) convertView
				.findViewById(R.id.select_CheckBox);
		
		chk.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				// TODO Auto-generated method stub
				mlist.get(position).setIsselected(isChecked);
			}
		});
		
		tvName.setText(mlist.get(position).getName());
		tvPhone.setText(mlist.get(position).getPhoneno());
		return convertView;
	}

	public void setDatas(List<ContactBean> list){
		mlist = list;
		notifyDataSetChanged();
	}
}
